package com.cwt_taxi_xa;

import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.cwt_taxi_xa.protocol.DeviceBiz;

public class MessageSetting extends CWTBaseActivity implements OnTouchListener{

	private static final String TAG = "MessageSetting";
	public RadioGroup rg_message_bg,rg_message_color,rg_message_show_type;
	public RadioButton rb_msg_bg_on,rb_msg_bg_off,rb_msg_color_green,
			rb_msg_color_write,rb_msg_show_move,rb_msg_show_silence;;
	public static Handler handler;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.messagesetting);

		initViews();
		initDate();
	}

	private void initViews() {
		// TODO Auto-generated method stub
		rg_message_bg = (RadioGroup) findViewById(R.id.rg_message_bg);
		rb_msg_bg_on = (RadioButton) findViewById(R.id.rb_msg_bg_on);
		rb_msg_bg_off = (RadioButton) findViewById(R.id.rb_msg_bg_off);
		rg_message_color = (RadioGroup) findViewById(R.id.rg_message_color);
		rb_msg_color_green = (RadioButton) findViewById(R.id.rb_msg_color_green);
		rb_msg_color_write = (RadioButton) findViewById(R.id.rb_msg_color_write);
		rg_message_show_type = (RadioGroup) findViewById(R.id.rg_message_show_type);
		rb_msg_show_move = (RadioButton) findViewById(R.id.rb_msg_show_move);
		rb_msg_show_silence = (RadioButton) findViewById(R.id.rb_msg_show_silence);

		rg_message_bg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(RadioGroup radiogroup, int i) {
				switch (i) {
					case R.id.rb_msg_bg_on:
						DeviceBiz.setMsgBgSwitcher(1);
						break;
					case R.id.rb_msg_bg_off:
						DeviceBiz.setMsgBgSwitcher(0);
						break;
					default:
						break;
				}
			}
		});
		rg_message_color.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(RadioGroup radiogroup, int i) {
				switch (i) {
					case R.id.rb_msg_color_write:
						DeviceBiz.setMsgColor(0);
						break;
					case R.id.rb_msg_color_green:
						DeviceBiz.setMsgColor(1);
						break;
					default:
						break;
				}
			}
		});
		rg_message_show_type.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(RadioGroup radiogroup, int i) {
				switch (i) {
					case R.id.rb_msg_show_move:
						DeviceBiz.setMsgShowType(0);
						break;
					case R.id.rb_msg_show_silence:
						DeviceBiz.setMsgShowType(1);
						break;
					default:
						break;
				}
			}
		});
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		handler = null;
	}

	/**
	 * 初始化数据
	 */
	public void initDate(){
		switch (DeviceBiz.getMsgBgSwitcher()) {
			case 0:	// 关闭
				rb_msg_bg_on.setChecked(false);
				rb_msg_bg_off.setChecked(true);
				break;
			case 1:	// 开启
				rb_msg_bg_on.setChecked(true);
				rb_msg_bg_off.setChecked(false);
				break;

			default:
				break;
		}

		switch (DeviceBiz.getMsgColor()) {
			case 0:	// 白色
				rb_msg_color_green.setChecked(false);
				rb_msg_color_write.setChecked(true);
				break;
			case 1:	// 绿色
				rb_msg_color_green.setChecked(true);
				rb_msg_color_write.setChecked(false);
				break;

			default:
				break;
		}

		switch (DeviceBiz.getMsgShowType()) {
			case 0:	// 滚动
				rb_msg_show_silence.setChecked(false);
				rb_msg_show_move.setChecked(true);
				break;
			case 1:	// 静止
				rb_msg_show_silence.setChecked(true);
				rb_msg_show_move.setChecked(false);
				break;

			default:
				break;
		}
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		return false;
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	public void setStatus(int index, boolean status) {
		// TODO Auto-generated method stub

	}

	@Override
	public void sendMsg(int type, Object obj) {
		// TODO Auto-generated method stub

	}
}
